﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace Tienda.Models
{
    public class CustomValidationRutEmpledo:ValidationAttribute
    {
        ViedojuegosEntities vj = new ViedojuegosEntities();
        Empleado per = new Empleado();

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value != null)
            {
                string valor = value.ToString();
                per = vj.Empleado.SingleOrDefault(v => v.Rut == valor);
                if (per != null)
                {
                    return ValidationResult.Success;
                }
                else
                {
                    return new ValidationResult("No Existe");
                }
            }
            return new ValidationResult("Ingrese Rut");
        }
    }
}